unit UformMain;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, uROClient, uROBinMessage, uROSuperTCPChannel,RLLibrary_Intf, DB,
  DBClient, StdCtrls, DBGridEhGrouping, GridsEh, DBGridEh,
  uROEventRepository, ExtCtrls, RzPanel, RzTabs;

type
  TfrmMain = class(TForm,IChatEvents)
    ROSuperTCPChannel: TROSuperTCPChannel;
    ROBinMessage: TROBinMessage;
    Button1: TButton;
    ClientDataSet1: TClientDataSet;
    DataSource1: TDataSource;
    ROEventReceiver: TROEventReceiver;
    RzStatusBar1: TRzStatusBar;
    RzPageControl1: TRzPageControl;
    TabSheet1: TRzTabSheet;
    TabSheet2: TRzTabSheet;
    TabSheet3: TRzTabSheet;
    RzToolbar1: TRzToolbar;
    procedure FormCreate(Sender: TObject);
    procedure Button1Click(Sender: TObject);
    procedure FormDestroy(Sender: TObject);
    procedure FormCloseQuery(Sender: TObject; var CanClose: Boolean);
  private
       IOrder:IOrderService;
  public
      procedure OnPhoneIn(const Channel: AnsiString; const PhoneNumber: AnsiString; const ReturnData: Variant);
  end;

var
  frmMain: TfrmMain;

implementation
    uses UfrmInCall;
{$R *.dfm}

procedure TfrmMain.FormCreate(Sender: TObject);
begin
  IOrder:=CoOrderService.Create(ROBinMessage,ROSuperTCPChannel);
  ROEventReceiver.RegisterEventHandlers([EID_ChatEvents],[Self]);
  ROEventReceiver.Active:=TRUE;
  
end;

procedure TfrmMain.Button1Click(Sender: TObject);
  var
     paramAr:ParamArray;
     param:ParamStruct;

begin
   param:=ParamStruct.Create;
   param.name:='spell';
   param.value:='whh';
   paramAr:=ParamArray.Create;
   paramAr.Add(param);
   ClientDataSet1.Data:= IOrder.GetClient( paramAr);

end;

procedure TfrmMain.OnPhoneIn(const Channel, PhoneNumber: AnsiString;
  const ReturnData: Variant);
begin
   with TfrmInCall.Create(nil) do
   begin
     ShowModal;
     Free;
   end;
 //  ShowMessage(Channel + PhoneNumber + VarToStr(ReturnData));
end;

procedure TfrmMain.FormDestroy(Sender: TObject);
begin
  ROEventReceiver.UnregisterEventHandlers([EID_ChatEvents]);
  ROEventReceiver.Active:=false;
end;

procedure TfrmMain.FormCloseQuery(Sender: TObject; var CanClose: Boolean);
begin
  ROSuperTCPChannel.Active:=false;
  Sleep(200);
end;

end.
